You point SMTP Proxy at your SMTP server(s) and configure your email
client(s) to send mail through the proxy (i.e. usually this means you use
localhost as the outgoing server).
To setup, enter appropriate values in your Spambayes configuration file in
the "SMTP Proxy" section (in particular: "remote_servers", "listen_ports",
and "use_cached_message"). This configuration can also be carried out via
the web user interface offered by POP3 Proxy and IMAP Filter.
To use, simply forward/bounce mail that you wish to train to the
appropriate address (defaults to spambayes_spam@localhost and
spambayes_ham@localhost). All other mail is sent normally.
(Note that IMAP Filter and POP3 Proxy users should not execute this script;
launching of SMTP Proxy will be taken care of by those applicatons).
There are two main forms of operation. With both, mail to two
(user-configurable) email addresses is intercepted by the proxy (and is
*not* sent to the SMTP server) and used as training data for a Spambayes
database. All other mail is simply relayed to the SMTP server.
If the "use_cached_message" option is False, the proxy uses the message
sent as training data. This option is suitable for those not using
POP3 Proxy or IMAP Filter, or for those that are confident that their
mailer will forward/bounce messages in an unaltered form.
If the "use_cached_message" option is True, the proxy examines the message
for a unique spambayes identification number. It then tries to find this
message in the pop3proxy caches and on the imap servers. It then retrieves
the message from the cache/server and uses *this* as the training data.
This method is suitable for those using POP3 Proxy and/or IMAP Filter, and
avoids any potential problems with the mailer altering messages before
forwarding/bouncing them.
To use, enter the required SMTP server data in your configuration file and
run sb_server.py
'''
__author__ = 'Tony Meyer <ta-meyer@ihug.co.nz>'
__credits__ = 'Tim Stone, all the Spambayes folk.'
try:
(True, False)
except NameError:
(True, False) = (1, 0)
todo = "\n o It would be nice if spam/ham could be bulk forwarded to the proxy,\n rather than one by one. This would require separating the different\n messages and extracting the correct ids. Simply changing to find\n *all* the ids in a message, rather than stopping after one *might*\n work, but I don't really know. Richie Hindle suggested something along\n these lines back in September '02.\n\n o Suggestions?\n\nTesting:\n\n o Test with as many clients as possible to check that the\n id is correctly extracted from the forwarded/bounced message.\n\nMUA information:\nA '*' in the Header column signifies that the smtpproxy can extract\nthe id from the headers only. A '*' in the Body column signifies that\nthe smtpproxy can extract the id from the body of the message, if it\nis there.\n Header Body\n*** Windows 2000 MUAs ***\nEudora 5.2 Forward * *\nEudora 5.2 Redirect *\nNetscape Messenger (4.7) Forward (inline) * *\nNetscape Messenger (4.7) Forward (quoted) Plain *\nNetscape Messenger (4.7) Forward (quoted) HTML *\nNetscape Messenger (4.7) Forward (quoted) Plain & HTML *\nNetscape Messenger (4.7) Forward (attachment) Plain * *\nNetscape Messenger (4.7) Forward (attachment) HTML * *\nNetscape Messenger (4.7) Forward (attachment) Plain & HTML * *\nOutlook Express 6 Forward HTML (Base64) *\nOutlook Express 6 Forward HTML (None) *\nOutlook Express 6 Forward HTML (QP) *\nOutlook Express 6 Forward Plain (Base64) *\nOutlook Express 6 Forward Plain (None) *\nOutlook Express 6 Forward Plain (QP) *\nOutlook Express 6 Forward Plain (uuencoded) *\nhttp://www.endymion.com/products/mailman Forward *\nM2 (Opera Mailer 7.01) Forward *\nM2 (Opera Mailer 7.01) Redirect * *\nThe Bat! 1.62i Forward (RFC Headers not visible) *\nThe Bat! 1.62i Forward (RFC Headers visible) * *\nThe Bat! 1.62i Redirect *\nThe Bat! 1.62i Alternative Forward * *\nThe Bat! 1.62i Custom Template * *\nAllegroMail 2.5.0.2 Forward *\nAllegroMail 2.5.0.2 Redirect *\nPocoMail 2.6.3 Bounce *\nPocoMail 2.6.3 Bounce *\nPegasus Mail 4.02 Forward (all headers option set) * *\nPegasus Mail 4.02 Forward (all headers option not set) *\nCalypso 3 Forward *\nCalypso 3 Redirect * *\nBecky! 2.05.10 Forward *\nBecky! 2.05.10 Redirect *\nBecky! 2.05.10 Redirect as attachment * *\nMozilla Mail 1.2.1 Forward (attachment) * *\nMozilla Mail 1.2.1 Forward (inline, plain) *1 *\nMozilla Mail 1.2.1 Forward (inline, plain & html) *1 *\nMozilla Mail 1.2.1 Forward (inline, html) *1 *\n\n*1 The header method will only work if auto-include original message\nis set, and if view all headers is true.\n"
import string
import re
import socket
import asyncore
import asynchat
import getopt
import sys
import os
import email
from spambayes import Dibbler
from spambayes import storage
from spambayes import message
from spambayes.tokenizer import textparts
from spambayes.tokenizer import try_to_repair_damaged_base64
from spambayes.Options import options
from sb_server import _addressPortStr, ServerLineReader
from sb_server import _addressAndPort
class SMTPProxyBase(Dibbler.BrighterAsyncChat):
"""An async dispatcher that understands SMTP and proxies to a SMTP
server, calling `self.onTransaction(command, args)` for each
transaction.
self.onTransaction() should return the command to pass to
the proxied server - the command can be the verbatim command or a
processed version of it. The special command 'KILL' kills it (passing